home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / HDX_BACK / HDX350 / PART.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  8.0 KB  |  408 lines

  1. /* part.c */
  2.  
  3.  
  4. /*
  5.  * 24-Nov-88    jye.     change and add codes so that can be used for MS-DOS
  6.  */
  7. #include "obdefs.h"
  8. #include "gemdefs.h"
  9. #include "osbind.h"
  10. #include "mydefs.h"
  11. #include "part.h"
  12. #include "bsl.h"
  13. #include "hdx.h"
  14. #include "addr.h"
  15.  
  16.  
  17. extern char sbuf[];
  18. extern int npart;
  19. extern int uplim;
  20. extern long bslsiz;
  21. extern long gbslsiz();
  22. extern int noinfo;        /* 1: no information inside the wincap */
  23.  
  24. /*
  25.  * Complain about partition error.
  26.  *
  27.  */
  28. parterr(devno)
  29. int devno;
  30. {
  31.     char *pdev="X";
  32.     int tmp;
  33.     
  34.     if (devno > 7) tmp = devno - 8;
  35.     *pdev = tmp + '0';
  36.     (cantpart[PTNDEV].ob_spec)->te_ptext = pdev;
  37.     cantpart[PTNERROK].ob_state = NORMAL;
  38.     execform(cantpart);
  39.     return ERROR;
  40. }
  41.  
  42.  
  43. /*
  44.  * Fill in partition entry with default information
  45.  * and configuration values from the current "pr" wincap entry.
  46.  *
  47.  */
  48. fillpart(n, part)
  49. int n;
  50. PART *part;
  51. {
  52.     long num;
  53.     char *partid;
  54.     char *idstr = "XX";
  55.     char *wgetstr();
  56.  
  57.     idstr[1] = n + '0';
  58.  
  59.     /* see if `pX' is mentioned */
  60.     *idstr = 'p';
  61.     if (wgetnum(idstr, &num) == OK)
  62.     {
  63.     /* do the ST partition assignment */
  64.         npart++;
  65.         part->p_siz = (LONG)(num / 512);
  66.            part->p_flg = P_EXISTS;
  67.         if (part->p_siz < MB16)    {
  68.             part->p_id[0] = 'G';
  69.             part->p_id[1] = 'E';
  70.             part->p_id[2] = 'M';
  71.         } else {
  72.             part->p_id[0] = 'B';
  73.             part->p_id[1] = 'G';
  74.             part->p_id[2] = 'M';
  75.         }
  76.     }
  77. }
  78.  
  79.  
  80. /* set the partition informations to the partition structures */
  81.  
  82. setpart(part, pnam, hsize)
  83. PART *part;
  84. char *pnam;
  85. long hsize;
  86. {
  87.     long onepart, remain;
  88.     int i;
  89.  
  90.     npart = 4;
  91.     if ((!noinfo) && (*pnam))     {
  92.         /* there is a partition scheme inside the wincap */
  93.         msetpart(part, pnam, hsize);
  94.         return OK;
  95.     }
  96.     onepart = hsize/4;
  97.     remain = (hsize - onepart * 4) / 4;
  98.     for ( i = 0; i < 4; i++, part++)    {
  99.         if (i == 4)    {
  100.             part->p_siz = hsize - (onepart + remain) * 3;
  101.         } else {
  102.             part->p_siz = onepart+remain;
  103.         }
  104.            part->p_flg = P_EXISTS;
  105.         if (part->p_siz < MB16)    {
  106.                part->p_id[0] = 'G';
  107.                part->p_id[1] = 'E';
  108.                part->p_id[2] = 'M';
  109.         } else {
  110.                part->p_id[0] = 'B';
  111.                part->p_id[1] = 'G';
  112.                part->p_id[2] = 'M';
  113.         }
  114.     }
  115. }
  116.  
  117. /* set the partition informations from the 'pname'.     */
  118. /* For example, pname = 12-12-14-14                        */        
  119.  
  120. msetpart(part, pname, hsize)
  121. PART *part;
  122. char *pname;
  123. long hsize;
  124. {
  125.     long part1, part2, part3, part4, remain;
  126.     int i, np;
  127.  
  128.     npart = 4;
  129.     np = 4;
  130.     convs2i(pname, &part1, 1);        /* 1: get first ASCII */
  131.     if (convs2i(pname, &part2, 2) == 1)        {        /* 2: get second ASCII */
  132.         /* only one partition */
  133.         part2 = 0;
  134.         part3 = 0;
  135.         part4 = 0;
  136.         np = 1;
  137.     } else if (convs2i(pname, &part3, 3) == 2)    {    /* 3: get third ASCII */
  138.         /* only two partitions */
  139.         part3 = 0;
  140.         part4 = 0;
  141.         np = 2;
  142.     } else if (convs2i(pname, &part4, 4) == 3)    {    /* 4: get fourth ASCII */
  143.         /* only three partitions */
  144.         part4 = 0;
  145.         np = 3;
  146.     }
  147.     remain = (hsize - (part1 + part2 + part3 + part4)) / np;
  148.     if (np == 1)    {
  149.         part1 = hsize;
  150.     } else if (np == 2)    {
  151.         part1 += remain;
  152.         part2 = hsize - part1;
  153.     } else if (np == 3)    {
  154.         part1 += remain;
  155.         part2 += remain;
  156.         part3 = hsize - part1 - part2;
  157.     } else {
  158.         part1 += remain;
  159.         part2 += remain;
  160.         part3 += remain;
  161.         part4 = hsize - part1 - part2 - part3;
  162.     }
  163.     for ( i = 0; i < 4; i++, part++)    {
  164.         switch(i)    {
  165.             case 0:    part->p_siz = part1;
  166.                     break;
  167.             case 1:    part->p_siz = part2;
  168.                     break;
  169.             case 2:    part->p_siz = part3;
  170.                     break;
  171.             case 3:    part->p_siz = part4;
  172.                     break;
  173.         }
  174.         if (!part->p_siz) continue;
  175.            part->p_flg = P_EXISTS;
  176.         if (part->p_siz < MB16)    {
  177.                part->p_id[0] = 'G';
  178.                part->p_id[1] = 'E';
  179.                part->p_id[2] = 'M';
  180.         } else {
  181.                part->p_id[0] = 'B';
  182.                part->p_id[1] = 'G';
  183.                part->p_id[2] = 'M';
  184.         }
  185.     }
  186. }
  187.  
  188.  
  189. /* conver the string 12-12-14-14 to a integer */
  190.  
  191. convs2i(pname, num, flag)
  192.  
  193. char *pname;
  194. long *num;
  195. int flag;        /* 1: conver the first one. 3: conver the third one */
  196.  
  197. {
  198.     char tem[10], *ptr;
  199.     int i;
  200.     UWORD n=0;
  201.  
  202.     ptr = pname;
  203.     for (i = 0; i < 10; i++)
  204.         tem[i] = "\0";
  205.  
  206.     if (flag == 2)    {    /* conver the second one of pname */
  207.         while ((*ptr != '-') && (*ptr))      ptr++;
  208.         if (!*ptr)  return 1;    /* only one partition */
  209.         ptr++;
  210.     } else if (flag == 3)    {    /* conver the third one of 12-12-14-14 */
  211.         while (*ptr != '-')     ptr++;
  212.         ptr++;
  213.         while ((*ptr != '-') && (*ptr))      ptr++;
  214.         if (!*ptr) return 2;        /* only two partitions */
  215.         ptr++;
  216.     } else if (flag == 4)    {
  217.         while (*ptr != '-')     ptr++;
  218.         ptr++;
  219.         while (*ptr != '-')     ptr++;
  220.         ptr++;
  221.         while ((*ptr != '-') && (*ptr))      ptr++;
  222.         if (!*ptr) return 3;        /* only three partitions */
  223.         ptr++;
  224.     }
  225.     /* copy the string into the buf */
  226.     for (i = 0; (*ptr != '-')&&(*ptr); )    {
  227.         tem[i++] = *ptr++;
  228.     }
  229.  
  230.     /* conver the string to integer */
  231.     for (i = 0; tem[i] >= '0' && tem[i] <= '9'; ++i)
  232.         n = 10 * n + (UWORD)(tem[i] - '0');
  233.  
  234.     *num = (long)n * 2048;
  235.     if (!n) return(flag - 1);
  236.     return OK;
  237. }
  238.  
  239.  
  240.  
  241. /* set the menu partition scheme */
  242.  
  243. setschm(dsize, partnames)
  244.  
  245. long dsize;
  246. char *partnames;
  247.  
  248. {
  249.     int part12;
  250.     int part34;
  251.     int tmp1, tmp2;
  252.     int i, siz, index=2;
  253.  
  254.     siz = dsize/2048;
  255.     for (i = 0; i < NAMSIZ; i++)    {
  256.         partnames[i] = '\0';
  257.     }
  258.     tmp1 = dsize/(2048*4);
  259.     tmp2 = (siz - tmp1*4)/4;
  260.     itoas(partnames, tmp1+tmp2, 0);
  261.     itoas(partnames, tmp1+tmp2, 1);
  262.  
  263.     if (siz > 47)    /* when index > 2, siz should > 47 */
  264.         index = siz/16;
  265.     part34 = dsize/(2048*4) - index;
  266.     part12 = part34 + 2*index;
  267.     for (i = 0; i < 4; i++)    {
  268.         if (!part34)        /* add the remainder into part12 */
  269.             part12 += (siz - 2 * part12) / 2;
  270.         itoas(partnames, part12, 0);
  271.         itoas(partnames, part34, 1);
  272.         if (part34 == 1)    {        
  273.             part12++;         /* add the remainder into part12 */
  274.             part34 = 0;
  275.         } else {
  276.             part34 -= index;
  277.             part12 += index;
  278.         }
  279.         if (part34 < 0) break;
  280.     }
  281. }
  282.  
  283.  
  284. /* convert the integer into ASCII and store it into a buffer like    */
  285. /* 12-12 if the integer is 12                                         */
  286.  
  287. itoas(buf, num, flag)
  288. char *buf;
  289. int num;
  290. int flag;         /* 1: put second part of scheme. Now buf = 12-12\0 */
  291.  
  292. {
  293.     int i=0, j;
  294.     char tem[10];
  295.  
  296.     if (*buf)    { /* 12-12-14-14\010-10\0 inside the buf */
  297.     skp:
  298.         while (*buf)    buf++;
  299.         if ((!flag) || (*(buf+1)))     buf++;        /* skip between string */
  300.         if (*buf)     {
  301.             goto skp;
  302.         }
  303.         if (flag)    {    /* put second part of scheme */ 
  304.             *buf++ = '-';
  305.         }
  306.     } 
  307.     /* conver the integer to ASCII */
  308.     do    {    /* generate digits in reverse order */
  309.         tem[i++] = num % 10 + '0';        /* get next digits */
  310.     } while ((num /= 10) > 0);            /* delete it */
  311.  
  312.     j = i;
  313.     for (; i > 0; )    {    /* reverse string 'buf' in place */
  314.         *buf++ = tem[--i];
  315.     }
  316.     *buf++ = '-';
  317.     for (; j > 0; )    {    /* reverse string 'buf' in place */
  318.         *buf++ = tem[--j];
  319.     }
  320.     *buf++ = '\0';
  321. }
  322.  
  323.  
  324. /*
  325.  * Force checksum of sector image to a value
  326.  */
  327. forcesum(image, sum)
  328. UWORD *image;
  329. UWORD sum;
  330. {
  331.     register int i;
  332.     register UWORD w;
  333.  
  334.     w = 0;
  335.     /* up limit is half of buffer size - 2 */
  336.     for (i = 0; i < ((UWORD)BPS/2 - 1); ++i)
  337.     w += *image++;
  338.     *image++ = sum - w;
  339. }
  340.  
  341.  
  342. /*
  343.  * Put word in memory in 8086 byte-reversed format.
  344.  *
  345.  */
  346. iw(wp, w)
  347. UWORD *wp;
  348. UWORD w;
  349. {
  350.     char *p;
  351.  
  352.     p = (char *)wp;
  353.     p[0] = (w & 0xff);
  354.     p[1] = ((w >> 8) & 0xff);
  355. }
  356.  
  357. /*
  358.  * Put long word in memory in 8086 word-reversed format.
  359.  *
  360.  */
  361. ilong(lp, l)
  362. long *lp;
  363. long l;
  364. {
  365.     UWORD *p;
  366.  
  367.     p = (UWORD *)lp;
  368.     iw(&p[0],(UWORD)(l & 0xffff));
  369.     iw(&p[1],(UWORD)((l >> 16) & 0xffff));
  370. }
  371.  
  372. /*
  373.  * Get long word in memory, from 8086 word-reversed format.
  374.  *
  375.  */
  376. glong(al, lp)   /* al is a swaped return long word,*/
  377.                 /* lp is a to be swaped long word */
  378. long *al;
  379. long *lp;
  380.  
  381. {
  382.    char *p, *q;
  383.  
  384.     p = (char *)al;
  385.     q = (char *)lp;
  386.     p[0] = q[3];
  387.     p[1] = q[2];
  388.     p[2] = q[1];
  389.     p[3] = q[0];
  390. }
  391.  
  392. /*
  393.  * Get word in memory, from 8086 byte-reversed format.
  394.  *
  395.  */
  396. UWORD gw(wp, aw)
  397. UWORD *wp;
  398. UWORD *aw;
  399. {
  400.     char *p, *q;
  401.  
  402.     p = (char *)wp;
  403.     q = (char *)aw;
  404.     q[0] = p[1];
  405.     q[1] = p[0];
  406.     return *aw;
  407. }
  408.